<#assign pageName="新增加班申请">
<@override name="head-styles">
</@override>
<@override name="page-content">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>${pageName}</legend>
    </fieldset>
    <form class="layui-form padding-10" lay-filter="formOvertimeAdd">
        <@ctrl.Textbox path="bsLeaveInfo.depName" labelText="所在部门" required="required" attributes="readonly"/>
        <@ctrl.Textbox path="bsLeaveInfo.empName" labelText="员工名称" required="required" attributes="readonly"/>
        <@ctrl.SingleSelect path="bsLeaveInfo.leaveType" labelText="请假类型" 
        	options=leaveTypeList text="name" value="id" required="required">
        	<option value="">—请选择—</option>
        </@ctrl.SingleSelect>
        <@ctrl.SingleSelect path="bsLeaveInfo.leaveCategory" labelText="请假类别" 
            options={"0":"按天请","1":"按小时请"} text="1" value="0" required="required">
            <option value="">—请选择—</option>
        </@ctrl.SingleSelect>
        <div id="forDate">
	        <@ctrl.Date path="bsLeaveInfo.startDate" labelText="开始时间" required="required"/>
	        <@ctrl.Date path="bsLeaveInfo.endDate" labelText="结束时间" required="required"/>
        </div>
        <div id="forDateTime"  style="display:none;">
	        <@ctrl.Date path="bsLeaveInfo.startDateT" labelText="开始时间" required="required"/>
	        <@ctrl.Date path="bsLeaveInfo.endDateT" labelText="结束时间" required="required"/>
        </div>
        <div id="forDay">
	        <@ctrl.Textbox path="bsLeaveInfo.leaveDays" labelText="请假天数"  attributes="readonly" unit="天"/>
        </div>
        <div id="forHour" style="display:none;">
	        <@ctrl.Textbox path="bsLeaveInfo.leaveHour" labelText="请假小时数"  attributes="readonly" unit="小时"/>
        </div>                     
         <@ctrl.Textbox path="bsLeaveInfo.sendUname" labelText="抄送人" required="required"/>  
        <@ctrl.Textarea path="bsLeaveInfo.reason" labelText="请假事由" required="required"/>
        <@ctrl.Textbox path="bsLeaveInfo.remark" labelText="备注"/>
        <@ctrl.Hidden path="bsLeaveInfo.depId"/>
        <@ctrl.Hidden path="bsLeaveInfo.empId"/>
        <@ctrl.Hidden path="bsLeaveInfo.id"/>
        <@ctrl.Hidden path="bsLeaveInfo.createUser"/>
        <@ctrl.Hidden path="bsLeaveInfo.createTime"/>
        <@ctrl.Hidden path="bsLeaveInfo.auditStatus"/>
        <@ctrl.Hidden path="bsLeaveInfo.auditUname"/>
        <@ctrl.Hidden path="bsLeaveInfo.auditUid"/>
        <@ctrl.Hidden path="bsLeaveInfo.sendUname"/>
        <@ctrl.Hidden path="bsLeaveInfo.processId"/>
        <@ctrl.FormAction backURL="../manage"/>
   </form>
</@override>
<@override name="page-scripts">
    <script>
        $(function(){
            layui.use(['form','layer','laydate','jquery'], function(){
                var form = layui.form;
                var layer=layui.layer;
                var laydate = layui.laydate;
                $=layui.jquery;
                laydate.render({
                    elem: '#startDate'
                    ,type: 'date'
                    ,format: 'yyyy-MM-dd'
                    ,trigger: 'click'
                });
                laydate.render({
                    elem: '#endDate'
                    ,type: 'date'
                    ,format: 'yyyy-MM-dd'
                    ,trigger: 'click'
                   	,done: (value) => {
                      		startDate = $("#startDate").val();
                       	endDate = value;
                       	depId = $("#depId").val();
                       	if(startDate == "" || endDate == ""){
                       		alert("开始时间和结束时间不能为空！");
                       	}else{
                       		$.ajax({
                   				type:'post',
                   				url : '${rc.getContextPath()}/attendance/leave/apply/calculationDay',
                   				data:{startDate:startDate,endDate:endDate,depId:depId},
                   				contentType: "application/x-www-form-urlencoded; charset=utf-8",
                   				success: function(time){
                   					if(time != ""){
                   						$("#leaveDays").val(time);
                   					}else{
                   						alert("开始时间和结束时间填写有误！！");						
                   					}						   					
                   				}
                   			})    	    		    		
                       	}        	 
                    }
                });
                laydate.render({
                    elem: '#startDateT'
                    ,type: 'datetime'
                    ,format: 'yyyy-MM-dd HH:mm'
                    ,trigger: 'click'
                });
                laydate.render({
                    elem: '#endDateT'
                    ,type: 'datetime'
                    ,format: 'yyyy-MM-dd HH:mm'
                    ,trigger: 'click'
                  	,done: function(value, date){ //监听日期被切换
                         	startDate = $("#startDateT").val();
                         	endDate = value;
                         	depId = $("#depId").val();
                         	if(startDate == "" || endDate == ""){
                         		alert("开始时间和结束时间不能为空！");
                         	}else{
                         		$.ajax({
                     				type:'post',
                     				url : '${rc.getContextPath()}/attendance/leave/apply/calculationHour',
                     				data:{startDate:startDate,endDate:endDate,depId:depId,},
                     				contentType: "application/x-www-form-urlencoded; charset=utf-8",
                     				success: function(time){
                     					if(time != ""){
                     						$("#leaveHour").val(time);
                     					}else{
                     						alert("开始时间和结束时间填写有误！！");						
                     					}						   					
                     				}
                     			})    	    		    		
                         	}
                     	}
                });
                //监听提交
                form.on('submit(submit)', function(data){
                    submitData(data.field, '${contextPath}/attendance/leave/apply/edit', function(){location.href="${contextPath}/attendance/leave/apply/manage";});
                    return false;
                });
                form.on('select(sendDep)',function(data){
                    var cityValue =  data.value;
                    var $region = "<option value=''>请选择抄送人</option>";
                    if(cityValue!=""){
                        $.post('${contextPath}/meeting/roomapply/apply/type/'+cityValue+'/query', {}, 
                        function(data){
                            $.each(data, function(index, item){
                                $region += "<option value='" + item.userId + "'>" + item.uname + "</option>";
                            })
                            $("#sendUid").html($region);
                            form.render("select");
                        })
                    }else{
                        $("#sendUid").html($region);
                        form.render("select");
                    }
                    $("#mendDep").val(cityValue);
                    $("#sendUid").trigger("change");
                });
                form.on('select(leaveCategory)',function(data){
                	var CValue =  data.value;
                	if(CValue == "0"){//按天请
                		$("#forDateTime").attr("style","display:none;");//隐藏div
                		$("#forDate").attr("style","display:block;");//显示
                		$("#startDateT").val();
                		$("#endDateT").val();
                	}
                	if(CValue == "1"){//按天请
                		$("#forDate").attr("style","display:none;");//隐藏div
                		$("#forDateTime").attr("style","display:block;");//显示
                		$("#startDate").val();
                		$("#endDate").val();
                	}
                });
            });
        })
         function calculationD() {
        	startDate = $("#startDate").val();
        	endDate = $("#endDate").val();
        	depId = $("#depId").val();
        	if(startDate == "" || endDate == ""){
        		alert("开始时间和结束时间不能为空！");
        	}else{
        		$.ajax({
    				type:'post',
    				url : '${rc.getContextPath()}/attendance/leave/apply/calculationDay',
    				data:{startDate:startDate,endDate:endDate,depId:depId},
    				contentType: "application/x-www-form-urlencoded; charset=utf-8",
    				success: function(time){
    					if(time != ""){
    						$("#leaveDays").val(time);
    					}else{
    						alert("开始时间和结束时间填写有误！！");						
    					}						   					
    				}
    			})    	    		    		
        	}        	 
		}; 
		function calculationH() {
        	startDate = $("#startDateT").val();
        	endDate = $("#endDateT").val();
        	depId = $("#depId").val();
        	if(startDate == "" || endDate == ""){
        		alert("开始时间和结束时间不能为空！");
        	}else{
        		$.ajax({
    				type:'post',
    				url : '${rc.getContextPath()}/attendance/leave/apply/calculationHour',
    				data:{startDate:startDate,endDate:endDate,depId:depId,},
    				contentType: "application/x-www-form-urlencoded; charset=utf-8",
    				success: function(time){
    					if(time != ""){
    						$("#leaveHour").val(time);
    					}else{
    						alert("开始时间和结束时间填写有误！！");						
    					}						   					
    				}
    			})    	    		    		
        	}        	 
		};
		$("#sendUname").mousedown(function() {
        	var ids = $('#sendUid').val();
	        layui.use('layer', function() {
	            layer.open({
	                type : 2,
	                title : false,
	                area : [ '60%', '70%' ],
	                content : '${contextPath}/common/showusers?ids='+ids	
	            });
	        });
	    })
	    function shareU(id,name){
	         $('#sendUid').val(id);
	         $('#sendUname').val(name);
	    };
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 
